using UnityEngine;
using System.Collections;

public class GameLogic : MonoBehaviour
{



    private static GameLogic instance;

    private string NextLevelName;

    private bool isReachedFinishLine = false;

    public GameObject HUD;

    private Music music;

    public GameObject InGameMenu;

    public GameObject Game;


    public static GameLogic Instance
    {
        get { return instance; }
    }

    void Awake()
    {
        if (instance != null)
        {
            if (instance.GetInstanceID() != this.GetInstanceID())
                //Destroy(this.gameObject);
                gameObject.SetActive(false);
        }

    }

    // Use this for initialization
    void Start()
    {
        Screen.sleepTimeout = SleepTimeout.NeverSleep;

        instance = this;



        //this.GetComponent<HUD>().AddButton("a");
        //this.GetComponent<HUD>().AddButton("a");
        //this.GetComponent<HUD>().AddButton("b");
    }

    // Update is called once per frame
    void Update()
    {

    }


    public void LevelEnded()
    {
        //   PlayerPrefs.Save();
        ShortMemory.Instance.LastRotation = Player.GetInstance().Ball.transform.rotation.eulerAngles;


        Application.LoadLevel(this.NextLevelName);

    }

    internal void HitBoundry()
    {
        if (!this.isReachedFinishLine)
            Application.LoadLevel(Application.loadedLevelName);
        else
            this.LevelEnded();
    }

    internal void FinishLineReached(string levelName)
    {
        this.StopMusic();
        this.NextLevelName = levelName;
        //PlayerPrefs.SetString(Application.loadedLevelName, "Done");
        this.isReachedFinishLine = true;
    }


    private void StopMusic()
    {
        Player.GetInstance().GetComponentInChildren<Music>().FinishLineReached();

    }
}
